import request from '@/utils/request'

export function login(data) {
	console.log(data)
	return request({
		url: 'admin/login', //注意请求方式及路径
		method: 'post',
		data
	})
}

export function getInfo(token) {
	return request({
		url: 'admin/admin',
		method: 'get',

	})
}
export function captcha() {
	return request({
		url: 'admin/captcha',
		method: 'get',

	})
}


export function getRoutes(token) {
	return request({
		url: 'admin/admin/role',
		method: 'get',

	})
}



export function formatRouter(routers){
  console.log('来改造',routers)
  const formatRouters = [];
  if(routers){
    routers.forEach(router => {
      console.log('去便利')
      const path = router.path;
      const name = router.name;
      const title = router.title;
      const component = router.component;
      const icon = router.icon;
      const formatRouter = {
        path: '/admin',
        component: Layout,
        redirect: '/admin/list',
         name: 'admin',
          meta: {
            title: '用户管理',
            icon: 'table'
          },
        children: [{
          path: path,
          name: name,
          component(resolve) {
            require(["@/views" + component], resolve)
          },
          meta: {
            title: title,
            icon: icon
          }
        }]
      };
      console.log('便利结束',formatRouter)
      formatRouters.push(formatRouter)
      console.log('改造结束',formatRouters)
    })
  }
 
  return formatRouters
}
